import 'package:flutter/material.dart';
import 'package:haokezufang/utils/string_is_null_empty.dart';
import 'package:scoped_model/scoped_model.dart';

import '../utils/store.dart';

///登录的token
class AuthLoginModel extends Model {
  late String _token;
  String get token => _token;
  bool get isLogin => _token != '';

  void initApp(BuildContext context) async {
    Store store = await Store.getInstance();
    String token = await store.getString(StoreKeys.token);
    if (!stringIsNullOrEmpty(token)) {
      login(token);
    }
  }

  void login(String token) {
    _token = token;
    notifyListeners();
  }

  void logOut() async {
    _token = '';
    Store store = await Store.getInstance();
    await store.setString(StoreKeys.token, '');
    notifyListeners();
  }
}
